package com.edu.exam.entity.assessment.generation;

import com.edu.exam.enums.assessment.generation.ConfigType;
import com.edu.exam.enums.assessment.generation.Scope;
import com.edu.exam.enums.assessment.generation.ConfigStatus;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

/**
 * 生成配置实体类
 * 所属模块：B-05 考核计划管理模块
 * 对应数据库表：generation_config
 *
 * <p>考核任务生成配置实体，记录自动生成任务的各种配置参数。
 * 包括生成规则、过滤条件、时间安排、优先级设置等配置信息。
 * 支持多种配置模板和自定义配置。</p>
 *
 * @author 系统生成
 * @version 2.0
 * @since 2025-11-09
 */
@Entity
@Table(name = "generation_config")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class GenerationConfig {

    /**
     * 配置ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 配置名称
     */
    @Column(name = "config_name", length = 100, nullable = false)
    private String configName;

    /**
     * 配置描述
     */
    @Column(name = "config_description", length = 500)
    private String configDescription;

    /**
     * 配置类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "config_type", length = 20, nullable = false)
    private ConfigType configType;

    /**
     * 配置版本
     */
    @Column(name = "version", length = 20)
    private String version;

    /**
     * 适用范围
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "scope", length = 20)
    private Scope scope;

    /**
     * 学期ID
     */
    @Column(name = "semester_id")
    private Long semesterId;

    /**
     * 学期名称
     */
    @Column(name = "semester_name", length = 100)
    private String semesterName;

    /**
     * 学年
     */
    @Column(name = "academic_year", length = 20)
    private String academicYear;

    /**
     * 院系ID
     */
    @Column(name = "department_id")
    private Long departmentId;

    /**
     * 院系名称
     */
    @Column(name = "department_name", length = 100)
    private String departmentName;

    /**
     * 专业ID
     */
    @Column(name = "major_id")
    private Long majorId;

    /**
     * 专业名称
     */
    @Column(name = "major_name", length = 100)
    private String majorName;

    /**
     * 课程ID
     */
    @Column(name = "course_id")
    private Long courseId;

    /**
     * 课程名称
     */
    @Column(name = "course_name", length = 100)
    private String courseName;

    /**
     * 班级ID
     */
    @Column(name = "class_id")
    private Long classId;

    /**
     * 班级名称
     */
    @Column(name = "class_name", length = 100)
    private String className;

    /**
     * 优先级
     */
    @Column(name = "priority")
    private Integer priority;

    /**
     * 状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "status", length = 20)
    private ConfigStatus status;

    /**
     * 配置参数(JSON格式)
     */
    @Column(name = "config_params", columnDefinition = "TEXT")
    private String configParams;

    /**
     * 规则配置(JSON格式)
     */
    @Column(name = "rules_config", columnDefinition = "TEXT")
    private String rulesConfig;

    /**
     * 过滤器配置(JSON格式)
     */
    @Column(name = "filter_config", columnDefinition = "TEXT")
    private String filterConfig;

    /**
     * 时间安排配置(JSON格式)
     */
    @Column(name = "schedule_config", columnDefinition = "TEXT")
    private String scheduleConfig;

    /**
     * 启用状态
     */
    @Column(name = "is_enabled")
    @Builder.Default
    private Boolean isEnabled = true;

    /**
     * 是否默认配置
     */
    @Column(name = "is_default")
    @Builder.Default
    private Boolean isDefault = false;

    /**
     * 是否模板
     */
    @Column(name = "is_template")
    @Builder.Default
    private Boolean isTemplate = false;

    /**
     * 模板分组
     */
    @Column(name = "template_group", length = 100)
    private String templateGroup;

    /**
     * 模板标签
     */
    @Column(name = "template_tags", length = 500)
    private String templateTags;

    /**
     * 使用次数
     */
    @Column(name = "usage_count")
    @Builder.Default
    private Integer usageCount = 0;

    /**
     * 最后使用时间
     */
    @Column(name = "last_used_time")
    private LocalDateTime lastUsedTime;

    /**
     * 备注
     */
    @Column(name = "remark", length = 1000)
    private String remark;

    /**
     * 删除标记
     */
    @Column(name = "is_deleted")
    @Builder.Default
    private Boolean isDeleted = false;

    /**
     * 创建人ID
     */
    @Column(name = "created_by", nullable = false)
    private Long createdBy;

    /**
     * 创建人姓名
     */
    @Column(name = "created_by_name", length = 100)
    private String createdByName;

    /**
     * 更新人ID
     */
    @Column(name = "updated_by")
    private Long updatedBy;

    /**
     * 更新人姓名
     */
    @Column(name = "updated_by_name", length = 100)
    private String updatedByName;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    /**
     * 审核人ID
     */
    @Column(name = "approved_by")
    private Long approvedBy;

    /**
     * 审核人姓名
     */
    @Column(name = "approved_by_name", length = 100)
    private    String approvedByName;

    /**
     * 审核时间
     */
    @Column(name = "approved_time")
    private LocalDateTime approvedTime;

}
